import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/automounting_provider.dart';
import 'package:xiongan_app_yy/provider/autopicking_provider.dart';
import 'package:xiongan_app_yy/provider/toreview_provider.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/into_warehousing_item.dart';
import 'package:xiongan_app_yy/widgets/search_widget.dart';

import 'out_warehousing.dart';

class OutWarehousingSearchPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return OutWarehousingSearchPageState();
  }
}

class OutWarehousingSearchPageState extends State<OutWarehousingSearchPage>{
  int size=0;
  List<dynamic> data;
  @override
  Widget build(BuildContext context) {
    return SearchWidget(tipsText: "请输入出库任务单号",onTapFuns: (value){
      if(value!=null&&value.toString().length>0){
        onSearch(value);
      }else{
        TostUtil.showToast("请输入出库任务单号");
      }

    },child: LoadBuilder(
    visibility: false,
    emptyVisibility: size == 0,
    emptyTextVisibility: size == 0,
    textEmptyTips: "暂无内容",
    builder: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return OutWareHousingItem(data[index], index,
                  (id, name) {
                if (name.contains("拣选")) {
                  Provider.of<AutoPickingProvider>(context)
                      .getDetailListData(orderid: id);
                  Navigator.pushNamed(
                      context, '/autopicking_type',arguments: id);
                } else if (name.contains("待复核")||name.contains("复核完成")||name.contains("已完成")) {
                  Provider.of<ToReviewProvider>(context)
                      .getDetailListData(orderid: id);
                  Navigator.of(context)
                      .pushNamed("/toreview_detail_list",arguments: data[index]);
                }/* else if (name.contains("待交接") ||name.contains("复核完成") || name == "已完成") {
                              Provider.of<OutHandoverDetailsInfoProvider>(context).getDetail(id);
                              Navigator.pushNamed(
                                  context, '/out_handover_details',
                                  arguments: _data[index]);
                            }*/
              });
        },
        separatorBuilder: (BuildContext context, int index) =>
            Divider(height: 1, color: Colors.transparent),
        itemCount: size)),
    );
  }

  void onSearch(String str) {
    InternetAPI.getInstance()
        .get("WMS/MiWarehouseOutOrder/GetAllMiWarehouseOutOrder", (value) {
      setState(() {
        data = value;
        size = data.length;
      });
    }, params: {
      'operaterUserId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      "userid": DataSingleton().Data.id,
      "warehouseid":DataSingleton().warehouseChoice.id,
      "appointmentmode":"20",
      "orderno":str,
      "pageNo":-1,
    });

  }
}